// 路由鉴权
import router from "./router/router";
// 进度条
import NProgress from "nprogress";

import "nprogress/nprogress.css"

// 取消进度条加载圆圈
NProgress.configure({ showSpinner: false });

// 前置守卫
router.beforeEach((to,from,next)=>{
  const token=localStorage.getItem('TOKEN')
  const doctoken=localStorage.getItem('DOCTOKEN')
  if(token){
    NProgress.start()
    next()
  }else{
    if(to.path=='/home'||to.path=='/doctor'||to.path=='/login'||to.path=='/reset'||to.path=='/reg'){
      next()
    }else if(to.path=='/chatuser'&&doctoken||to.path=='/showuser'&&doctoken){
      next()
    }else{
      next('/home')
      alert('请先登录')
    }
  }

})

// 后置路由
router.afterEach((to,form)=>{
  document.querySelector("body").setAttribute("style", "overflow: auto !important;background-color: #f2f2f2")
  NProgress.done()
})